package com.wngbms;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.cache.*;
import com.google.common.collect.*;
import com.google.common.util.concurrent.*;

import javax.annotation.Nullable;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class CollectionDemos {


    public static void main(String[] args) {

        List<String> list = Lists.newArrayList("a", "b", "c", "d", "8",  "", "abc");
        String join = Joiner.on(",").join(list);
        System.out.println(join);

        String t = "3,4,5,5,,,343,55,,34";
        List<String> strings = Splitter.on(",").splitToList(t);
        System.out.println(strings);

        List<Integer> l = Lists.newArrayList(1, 33, 5, 56, 6, 6, 3,  24, 2, 5, 56);
        List<List<Integer>> list1 = Lists.partition(l, 3);
        System.out.println(list1);

        Multimap<Integer, Integer> m = ArrayListMultimap.create();
        l.forEach(a -> m.put(a, a * 10));
        System.out.println(m);

        BiMap<String, Integer> w = HashBiMap.create();
//        w.put("f", 33);
        w.put("f", 1);
        w.put("s", 2);
        w.put("s", 22);
        w.put("t", 3);
        w.put("t", 33); // 抛异常, value不能重复
//
        System.out.println(w.get("s"));
        System.out.println(w.inverse().get(3));

//        Multiset<String> set = HashMultiset.create();
//
//        Multimap<String, String> map = HashMultimap.create();
////        Tables tables =
//
////        bidirectionalmap
//
//        LoadingCache<Object, Object> build = CacheBuilder.newBuilder().maximumSize(10).expireAfterWrite(10, TimeUnit.SECONDS)
//                .removalListener(new RemovalListener<Object, Object>() {
//                    @Override
//                    public void onRemoval(RemovalNotification<Object, Object> removalNotification) {
//
//                    }
//                }).build(new CacheLoader<Object, Object>() {
//                    @Override
//                    public Object load(Object o) throws Exception {
//                        return null;
//                    }
//                });
//
//        ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
//        ListenableFuture<Object> listenableFuture = service.submit(new Callable<Object>() {
//            @Override
//            public Object call() throws Exception {
//                return null;
//            }
//        });
//
//        Futures.addCallback(listenableFuture, new FutureCallback<Object>() {
//            @Override
//            public void onSuccess(@Nullable Object o) {
//
//            }
//
//            @Override
//            public void onFailure(Throwable throwable) {
//
//            }
//        });
    }
}
